package com.xyh.flowershop.controller;

import com.xyh.flowershop.annotations.RefreshToken;
import com.xyh.flowershop.constant.CommonConstant;
import com.xyh.flowershop.context.WebContext;
import com.xyh.flowershop.service.CommentService;
import com.xyh.flowershop.vo.req.comment.CommentPageReqVo;
import com.xyh.flowershop.vo.req.comment.CommentReqVo;
import com.xyh.flowershop.vo.resp.common.ResultRespVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;

/**
 * @author 小约翰可汗
 * @className CommentController
 * @createTime 2024/5/3020:56
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/comment/")
@Tag(name = "评论模块")
@RestController
@Slf4j
public class CommentController {

    private final CommentService commentService;

    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    @RefreshToken
    @Operation(description = "检查是否是买家")
    @GetMapping("check/{id}")
    public ResultRespVo checkIsBuyer(@PathVariable("id") String id){
        return ResultRespVo.success(commentService.checkIsBuyer(id));
    }

    @RefreshToken
    @Operation(description = "发布评论")
    @PostMapping("publishComment")
    public ResultRespVo publishComment(@RequestBody CommentReqVo vo) {
        log.info("用户编号: {}, 评论发布的信息: {}", WebContext.get(), vo);
        return ResultRespVo.success(commentService.publishComment(vo));
    }

    @Operation(description = "分页查询评论")
    @PostMapping("find/page")
    public ResultRespVo findCommentByPage(@RequestBody CommentPageReqVo vo) {
        log.info("用户编号: {}, 评论分页查询信息: {}", WebContext.get(), vo);
        return ResultRespVo.success(commentService.findCommentByPage(vo));
    }

//    @Operation(description = "评论总览")
//    @GetMapping("overview/{id}")
//    public ResultRespVo commentOverview(@PathVariable("id") String id) {
//        log.info("用户编号: {}, 评论总览信息: {}", WebContext.get(), id);
//        return ResultRespVo.success(commentService.commentOverview(id));
//    }

}
